package net.zjitc.controller;

import net.zjitc.domain.Category;
import net.zjitc.service.Impl.ServiceImpl;
import net.zjitc.service.Service;
import org.apache.commons.beanutils.BeanUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;

/**
 * Created by guo on 2017/11/12.
 */
@WebServlet(name = "AddCategoryServlet",urlPatterns = "/addCategoryServlet")
public class AddCategoryServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
      request.setCharacterEncoding("utf-8");
        Category category=new Category();
        try {
            BeanUtils.populate(category,request.getParameterMap());
            Service service=new ServiceImpl();
            int num= service.addCategory(category);
        } catch (Exception e) {
            e.printStackTrace();
        }
        response.sendRedirect("/shop/categoryServlet");
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
